package com.trkj.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.trkj.pojo.Emp;
import com.trkj.pojo.Overwork;
import com.trkj.service.OverWorkService;
import com.trkj.service.WorkFlowService;
import com.trkj.vo.OverWorkVo;

/**
 * 加班申请单
 * @author 彭帅
 *
 */
@Controller
@Transactional
@SessionAttributes({"emp", "funcIds"})
public class OverWorkController {
	@Autowired
	OverWorkService overWorkService;
	@Autowired
	WorkFlowService workFlowService;
	/**
	 * 填写加班申请单
	 * @return
	 */
	@RequestMapping("to_overwork")
	public String to_overwork() {
		return "to_overwork";
	}
	@RequestMapping("/get_overwork")
	@ResponseBody
	public OverWorkVo getOverwork(Model model) {
		Emp emp = (Emp) model.asMap().get("emp");
		Integer empid = emp.getEmpId();
		return overWorkService.overWorkVo(empid);
	}
	/**
	 * 加班申请暂存
	 * @param overwork
	 * @param empId
	 * @param deptId
	 * @param positionId
	 * @return
	 */
	@RequestMapping("/save_overwork")
	@ResponseBody
	public boolean save_overwork(Overwork overwork,Integer empId,Integer deptId,Integer positionId) {
		Integer isSave = overWorkService.save_overwork(overwork, positionId, empId, deptId);
		if (isSave!=0) {
			return true;
		}
		return false;
	}
	/**
	 * 加班申请提交
	 * @author Lixd
	 * @param overwork
	 * @param empId
	 * @param deptId
	 * @param positionId
	 * @return
	 */
	@RequestMapping("/submit_overwork")
	@ResponseBody
	public boolean submit_overwork(Overwork overwork,Integer empId,Integer deptId,Integer positionId,
			Model model,@RequestParam("pk")String processDefinitionKey) {
		Integer useid = getOnLineEmp(model);
		return overWorkService.submit_overwork(overwork, empId, deptId, positionId, useid, processDefinitionKey);
	}
	/**
	 * 借款部署流程接口
	 * @author Lixd
	 */
	@RequestMapping("/bushu_overwork")
	public void deploymentProcessDefinition_classpath() {
		workFlowService.deploymentProcessDefinition_classpath("人员加班流程",
				"diagrams/overwork_actProcess.png","diagrams/overwork_actProcess.bpmn");
	}
	/**
	 * 获取登录人的id
	 * @author Lixd
	 * @param model
	 * @return
	 */
	private Integer getOnLineEmp(Model model) {
		Emp emp = (Emp)model.asMap().get("emp");
		Integer useid = emp.getEmpId();
		return useid;
	}
}
